﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading.Tasks;

namespace LiuZhenJie
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("无参数构造函数 实例");
            Person ps1 = new Person();
            ps1.Print_Info();

            Console.WriteLine("有参数构造函数 实例");
            Person ps2 = new Person("刘振杰", 25);

            Console.ReadKey();
        }
    }

    public class Person
    {
        private string name;
        private int age;

        public string Name
        {
            get => name;
            set
            {
                if (value.Length > 10)
                {
                    name = value.Substring(0, 10);
                }
                else
                {
                    name = value;
                }
            }
        }

        public int Age
        {
            get => age;
            set
            {
                if (value >= 0 && value < 150)
                {
                    age = value;
                }
                else
                {
                    Console.WriteLine("age的值在0 - 149之间");
                }
            }
        }

        public Person() //无参构造函数
        {
            Name = "Not Name";
            Age = 0;
        }

        public Person(string name, int age) //初始化字段的构造函数，并打印信息
        {
            Name = name;
            Age = age;
            Print_Info();
        }

        public void Print_Info()    //打印信息
        {
            Console.WriteLine($"Name: {Name}, Age: {Age}");
        }
    }
}